local base = _G
module("Library.Utils.Utils")

lib = base.require("Library.Utils.Utils_lib")
base.print("Utils.lua loaded.\n")

function MessageBox(str,title,type)
	r = lib.Lua_MessageBox(str,title,type)
	return r
end

function System(cmd,para)
	if cmd == nil or para == nil then
		base.io.write("DBG:cmd or para is nil val!\n")
		return nil
	end
	base.io.write("DBG:Calling System() in Utils.lua with cmd: \"" .. cmd .. "\" and para: \"" .. para .. "\"\n")
	r = lib.Lua_System(cmd,para)
	return r
end

function Base64_Encode(str)
	if str == nil then
		base.io.write("DBG:str is nil val!\n")
		return nil
	end
	r = lib.Lua_Base64_Encode(str)
	return r
end

function Base64_Decode(str)
	if str == nil then
		base.io.write("DBG:str is nil val!\n")
		return nil
	end
	r = lib.Lua_Base64_Decode(str)
	return r
end

function UnicodeToGBK(str)
	if str == nil then
		base.io.write("DBG:str is nil val!\n")
		return nil
	end
	r = lib.Lua_UnicodeToGBK(str)
	return r
end

function GBKToUnicode(str)
	if str == nil then
		base.io.write("DBG:str is nil val!\n")
		return nil
	end
	r = lib.Lua_GBKToUnicode(str)
	return r
end

function SplitString(szFullString, szSeparator)
	if szFullString == nil or szSeparator == nil then
		return nil
	end
	local nFindStartIndex = 1
	local nSplitIndex = 1
	local nSplitArray = {}
	while true do
	   local nFindLastIndex = base.string.find(szFullString, szSeparator, nFindStartIndex)
	   if not nFindLastIndex then
	    nSplitArray[nSplitIndex] = base.string.sub(szFullString, nFindStartIndex, base.string.len(szFullString))
	    break
	   end
	   nSplitArray[nSplitIndex] = base.string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1)
	   nFindStartIndex = nFindLastIndex + base.string.len(szSeparator)
	   nSplitIndex = nSplitIndex + 1
	end
	return nSplitArray
end